`
https://leetcode.cn/problems/minimized-maximum-of-products-distributed-to-any-store/
`

/**
 * @param {number} n
 * @param {number[]} quantities
 * @return {number}
 */
var minimizedMaximum = function (n, quantities) {

  // 每个商店商品数量都 <= k，分配的商店数能否 <= n
  const check = (k) => {
    let count = 0
    for (const q of quantities) {
      count += Math.ceil(q / k)
    }
    return count <= n
  }

  let left = 0, right = Math.max(...quantities)
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (check(mid)) {
      // 每个商店分配到的商品还能再降
      right = mid
    } else {
      // 不够分
      left = mid
    }
  }
  return right
};